package com.example.ffepeg.Ikanalyzer;

import java.util.List;
import java.util.ArrayList;

public class GroupingExample {
    public static void main(String[] args) {
        // 给定的元素列表
        List<String> elements = List.of("ai", "地貌", "使", "山地", "别墅",
                "456", "形体", "极其丰富", "test123", "阿道夫",
                "工人房", "阿斯蒂", "空滤壳");
        List<List<String>> groupedElements = groupIntoSublists(elements, 7);
        printGroupedElements(groupedElements);
    }

    private static List<List<String>> groupIntoSublists(List<String> list, int groupSize) {
        List<List<String>> grouped = new ArrayList<>();
        int size = list.size();
        // 开始分组
        for (int i = 0; i < size; i += groupSize) {
            int end = Math.min(i + groupSize, size);
            grouped.add(new ArrayList<>(list.subList(i, end)));
        }

        return grouped;
    }

    private static void printGroupedElements(List<List<String>> groupedElements) {
        List<String> list = new ArrayList<>();
        // 打印分组后的元素
        for (List<String> groupedElement : groupedElements) {
            StringBuilder builder = new StringBuilder();
            System.out.println("Group: " + groupedElement);
            for (String item : groupedElement){
                builder.append(item);
            }
            list.add(builder.toString());
        }
        System.out.println("List数据为: "+ list);

    }


}
